<?php
  class Ortho{
       
       private $id;
       private $nom;
       private $prenom;
       private $adresse;
       private $cp;
       private $ville;
       private $mail;
       private $fax;
       private $tel;
       private $id_vente;
       private $statut;
       
       public function __construct($id_ortho){
           $this->id = $id_ortho;
           
           $db = new Db();
           $req = $db->query("SELECT *
                              FROM ortho
                              WHERE id_ortho ='".$id_ortho."';");   
           $res = mysql_fetch_object($req);
             
           $this->id = $id_ortho;
           $this->nom = $res->nom_ortho;
           $this->prenom = $res->prenom_ortho;
           $this->adresse = $res->adresse_ortho;
           $this->cp = $res->cp_ortho;
           $this->ville = $res->ville_ortho;
           $this->fax = $res->fax_ortho;
           $this->mail = $res->mail_ortho;  
           
           $req = $db->query("SELECT *
                              FROM vente_ortho
                              WHERE id_ortho ='".$id_ortho."';");  
           $res = mysql_fetch_object($req); 
           
           $this->id_vente = $res->id_vente_ortho;
           $this->statut = $res->statut_vente;
                           
       }
       
       // Getters
       
     public function get_statut(){
        return $this->statut;
     }
     
     public function get_id_vente(){
        return $this->id_vente;
     }
     
    
     public function get_id(){
         return $this->id;
     }
        
     public function get_nom(){
         return $this->nom;
     }
     
     public function get_adresse(){
         return $this->adresse;
     }
     
     public function get_cp(){
        return $this->cp;
     }
     
     public function get_ville(){
        return $this->ville;
     }
     
     public function get_mail(){
         return $this->mail;
     }
     
     public function get_tel(){
         return $this->tel;
     }
     
     public function get_fax(){
         return $this->fax;
     }
     
     public function changer_statut($statut){
        $db = new Db();
        $req = $db->query("UPDATE vente_ortho SET statut = '$statut' WHERE id_ecole='".$this->get_id()."';");
     }    
     
     public function effacer_vente(){
         $db = new Db();
         $db->query("DELETE FROM achete 
                     WHERE id_vente = (
                        SELECT id_vente_ortho
                        FROM vente_ortho
                        WHERE id_ortho = '".$this->get_id()."'
                     );");
         $db->query("DELETE 
                     FROM vente_ortho 
                     WHERE id_ortho = '".$this->get_id()."';");
         
     }
  }
?>
